<?php
$hostname='localhost';
$user='root';
$password='';
$dbname='cyberlinks';

mysql_connect($hostname,$user,$password)or die(mysql_error());
mysql_select_db($dbname);

#####status###3
function getStatus($status=0) {
    return  $status == 0 ? '<span class="glyphicon glyphicon-star-empty" style="font-size:30px; color: #CC9900;"></span>' : '<span class="glyphicon glyphicon-star" style="font-size:30px; color: green;"></span>';
  }
###end####
####Updatebyid#######3
  function updateById($tableName='',$data=array(),$id=0){

    if(empty($tableName) || empty($data)) {
      return false;
    }

    $subQuery = '';
    foreach ($data as $columnName => $colValue) {
      $subQuery .= " `$columnName`='$colValue',";
    }
    $subQuery = rtrim($subQuery,', ');
    $query = "UPDATE `$tableName` SET $subQuery WHERE `id`=$id";
   
    mysql_query($query) or die(mysql_error());
    return mysql_affected_rows();
	
  }
##end#####

#####Fetch######

  function fetchAll($table = '',$where='',$order='',$limit='',$offset=0)
  {
    if($offset != 0){
      $limit = "LIMIT $limit,$offset";
    }

    if($order != '') {
      $order = "ORDER BY $order";
    }

    if($where != '') {
      $where = "WHERE  $where";
    }

    $query = "SELECT * FROM $table  $where $order $limit";

    $result = mysql_query($query) or die(mysql_error());
    return $result;
  }//fetchAll()
  function success($msg='')
  {
    return "<div class=\"alert alert-success alert-dismissable\">  <button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">&times;</button><strong>$msg</strong></div>";
  }

  function error($msg='')
  {
    return "<div class=\"alert alert-danger alert-dismissable\">  <button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">&times;</button><strong>$msg</strong></div>";
  }

####function for insert#####
  function insert($tableName='',$data=array())
  {
    $query = "INSERT INTO `$tableName` SET";
    $subQuery = '';
    foreach ($data as $columnName => $colValue) {
      $subQuery .= " `$columnName`='$colValue',";
    }
    $subQuery = rtrim($subQuery,', ');
    $query .= $subQuery;
  
    mysql_query($query) or die(mysql_error());
    return mysql_insert_id();
  }//end insert


#######Function For Delete #####
function deleteby($table = '', $id='')
{
	$query="DELETE FROM $table WHERE id='$id'";
	mysql_query($query)or die(mysql_error());
	return mysql_affected_rows();
}
#####DELETE end ########

#### Function For Count records ######
function CountAll($tableName = '', $where='')
{
if($where != '') {
      $where = "WHERE  $where";
    }
$query = "SELECT COUNT(*) as `total` FROM `$tableName` $where";
    $result = mysql_query($query)or die(mysql_error());
    $ans = mysql_fetch_assoc($result);
    return $ans['total'];

	
}
?>